import { defHttp } from '@/utils/http/axios';
import { useI18n } from '@/hooks/web/useI18n';

const { t } = useI18n();
enum Api {
  getpageListAPI = '/mv/type/page',
  AddpageListAPI = '/mv/type/add',
  DeletepageListAPI = '/mv/type/delete',
  getTasklistAPI = '/mv/task/page',
  AddTaskpageListAPI = '/mv/task/add',
  getDetailAPI = '/mv/data/matchPage',
  stopTaskAPI = '/mv/task/stopTask',
  getMatchMaxAPI = '/mv/data/getMatchMax',
  taskStatusNumApi = '/mv/task/taskStatusNum',
  matchNodeDetailAPI = '/mv/task/matchNodeDetail',
  OnematchNodeDetailAPI = '/mv/task/matchTaskDetail',
  matchCategory = '/mv/data/matchCategory',
  finishTaskAPI = '/mv/task/finishTask',
  matchListAPI = '/mv/data/matchList',
  categorAPI="/mv/task/category",
  dataTaskPageAPI='/mv/data/dataTaskPage',
  SubcreateTaskAPI='/mv/taskMarket/createTask',
  taskMarketPageAPI='/mv/taskMarket/page'
}

//获取匹配规则
export function getlistAPI(params) {
  params['current'] = params.page;
  params['size'] = params.pageSize;
  return defHttp
    .post(
      {
        url: Api.getpageListAPI,
        params,
      },
      {
        isTransformResponse: false,
      },
    )
    .then((res) => {
      const { records, total } = res.data;

      return {
        items: records, // 将数据列表赋值给 items
        total, // 直接使用 total
      };
    })
    .catch((err) => {
      console.log(err, '用户信息');
    });
}

//获取人员匹配
export function taskMarketPageAPI(params) {
  params['current'] = params.page;
  params['size'] = params.pageSize;
  return defHttp
    .post(
      {
        url: Api.taskMarketPageAPI,
        params,
      },
      {
        isTransformResponse: false,
      },
    )
    .then((res) => {
      const { records, total } = res.data;
      return {
        items: records, // 将数据列表赋值给 items
        total, // 直接使用 total
      };
    })
    .catch((err) => {
      console.log(err, '用户信息');
    });
}

//添加匹配规则
export function AddpageListAPI(params) {
  return defHttp
    .post(
      {
        url: Api.AddpageListAPI,
        params,
      },
      {
        isTransformResponse: false,
      },
    )
    .then((res) => {
      return res;
    })
    .catch((err) => {
      console.log(err, '添加用户');
    });
}

//人员匹配
export function SubcreateTaskAPI(params) {
  return defHttp
    .post(
      {
        url: Api.SubcreateTaskAPI,
        params,
      },
      {
        isTransformResponse: false,
      },
    )
    .then((res) => {
      return res;
    })
}

//删除匹配规则

export function DeletepageListAPI(params) {
  return defHttp
    .get(
      {
        url: Api.DeletepageListAPI + '?id=' + params.id,
      },
      {
        isTransformResponse: false,
      },
    )
    .then((res) => {
      return res;
    })
    .catch((err) => {
      console.log(err, '删除匹配规则');
    });
}

//获取分组信息
export function matchCategory() {
  return defHttp
    .get(
      {
        url: Api.matchCategory,
      },
      {
        isTransformResponse: false,
      },
    )
    .then((res) => {
      return res;
    });
}

//获取关键字 

export function categorAPI(params) {
  return defHttp
    .get(
      {
        url: Api.categorAPI+'?category='+params,
      },
      {
        isTransformResponse: false,
      },
    )
    .then((res) => {
      return res;
    });
}

//获取匹配信息列表
export function getTasklistAPI(params) {
  params['current'] = params.page;
  params['size'] = params.pageSize;
  return defHttp
    .post(
      {
        url: Api.getTasklistAPI,
        params,
      },
      {
        isTransformResponse: false,
      },
    )
    .then((res) => {
      const { records, total } = res.data;

      return {
        items: records, // 将数据列表赋值给 items
        total, // 直接使用 total
      };
    })
    .catch((err) => {
      console.log(err, '用户信息');
    });
}

//添加匹配信息
export function AddTaskpageListAPI(params) {
  return defHttp
    .post(
      {
        url: Api.AddTaskpageListAPI,
        params,
      },
      {
        isTransformResponse: false,
      },
    )
    .then((res) => {
      return res;
    })
    .catch((err) => {
      console.log(err, '添加用户');
    });
}

//获取详情
export function getDetailAPI(params) {
  params['current'] = params.page;
  params['size'] = params.pageSize;
  return defHttp
    .post(
      {
        url: Api.getDetailAPI,
        params,
      },
      {
        isTransformResponse: false,
      },
    )
    .then((res) => {
      const { records, total } = res.data;
      console.log(records, '123');
      return {
        items: records, // 将数据列表赋值给 items
        total, // 直接使用 total
      };
    })
    .catch((err) => {
      console.log(err, t('sys.script.details'));
    });
}

//停止任务 stopTaskAPI
export function stopTaskAPI(params) {
  return defHttp
    .get(
      {
        url: Api.stopTaskAPI + '?taskId=' + params.id,
      },
      {
        isTransformResponse: false,
      },
    )
    .then((res) => {
      return res;
    })
    .catch((err) => {
      console.log(err, '添加用户');
    });
}
//获取前五的匹配任务
export function getMatchMaxAPI(params) {
  return defHttp
    .get(
      {
        url: Api.getMatchMaxAPI + '?taskId=' + params,
      },
      {
        isTransformResponse: false,
      },
    )
    .then((res) => {
      return res;
    })
    .catch((err) => {
      console.log(err, '获取前五的匹配任务');
    });
}

//获取信息匹配里面各状态的数据
export function taskStatusNumApi() {
  return defHttp
    .get(
      {
        url: Api.taskStatusNumApi,
      },
      {
        isTransformResponse: false,
      },
    )
    .then((res) => {
      return res;
    })
    .catch((err) => {
      console.log(err, '获取数据');
    });
}

// 获取节点信息
export function matchNodeDetailAPI(params) {
  return defHttp
    .get(
      {
        url: Api.matchNodeDetailAPI + '?taskId=' + params.taskId,
      },
      {
        isTransformResponse: false,
      },
    )
    .then((res) => {
      return res;
    });
}
//一阶段详情
export function OnematchNodeDetailAPI(params) {
  return defHttp
    .post(
      {
        url: Api.OnematchNodeDetailAPI,
        params,
      },
      {
        isTransformResponse: false,
      },
    )
    .then((res) => {
      return res;
    });
}

//获取所有的视频
  export function matchListAPI(params) {
    return defHttp
      .post(
        {
          url: Api.matchListAPI,
          params,
        },
        {
          isTransformResponse: false,
        },
      )
      .then((res) => {
        return res;
      });
  }

//提前完成采集

export function finishTaskAPI(params) {
  return defHttp
    .get(
      {
        url: `${Api.finishTaskAPI}?taskId=${params}`,
      },
      {
        isTransformResponse: false,
      },
    )
    .then((res) => {
      return res;
    });
}
//获取一阶段视频数据 
export function dataTaskPageAPI(params) {
  return defHttp
    .post(
      {
        url: Api.dataTaskPageAPI,
        params,
      },
      {
        isTransformResponse: false,
      },
    )
    .then((res) => {
      return res;
    });
}

